home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / encrypt / testapp.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-05-22  |  1.5 KB  |  64 lines

  1. #include <stdio.h>
  2.  
  3. #import "Encrypt.tlb"
  4. using namespace YuriEncrypt;
  5.  
  6.  
  7. struct StartUpCom {
  8.     StartUpCom() { CoInitialize(NULL); }
  9.     ~StartUpCom() { CoUninitialize(); }
  10. } _global_com_inst;
  11.  
  12. void dump_com_error(_com_error &e)
  13. {
  14.     printf("COM error\n");
  15.     printf("\tCode = %08lx\n", e.Error());
  16.     printf("\tCode meaning = %s\n", e.ErrorMessage());
  17.     _bstr_t bstrSource(e.Source());
  18.     _bstr_t bstrDescription(e.Description());
  19.     printf("\tSource = %s\n", (LPCTSTR) bstrSource);
  20.     printf("\tDescription = %s\n", (LPCTSTR) bstrDescription);
  21. }
  22.  
  23. void main(int argc, char **argv)
  24. {
  25.     IMD5Ptr pMD5;
  26.     IMD4Ptr pMD4;
  27.  
  28.     char *szIn[] = {
  29.         "",
  30.         "a",
  31.         "abc",
  32.         "message digest",
  33.         "abcdefghijklmnopqrstuvwxyz",
  34.         "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
  35.         "12345678901234567890123456789012345678901234567890123456789012345678901234567890"
  36.     };
  37.  
  38.     _bstr_t bstr("test");
  39.  
  40.     BSTR b(bstr);
  41.  
  42.     try {
  43.         HRESULT hr = pMD5.CreateInstance(__uuidof(MD5));
  44.         if (FAILED(hr)) _com_issue_error(hr);
  45.  
  46.         for (int i = 0; i < 7; i++) {
  47.             _bstr_t bsOut = pMD5->Encrypt(szIn[i]);
  48.             printf("MD5(%s) = %s\n\n", szIn[i], (char*)bsOut);
  49.         }
  50.  
  51.         hr = pMD4.CreateInstance(__uuidof(MD4));
  52.         if (FAILED(hr)) _com_issue_error(hr);
  53.  
  54.         for (i = 0; i < 7; i++) {
  55.             _bstr_t bsOut = pMD4->Encrypt(szIn[i]);
  56.             printf("MD4(%s) = %s\n\n", szIn[i], (char*)bsOut);
  57.         }
  58.     } 
  59.     catch(_com_error& e) {
  60.         dump_com_error(e);
  61.         return;
  62.     }
  63. }
  64.